package com.socene.kotlin.controller

import com.socene.kotlin.entity.User
import com.socene.kotlin.service.UserService
import io.swagger.annotations.Api
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.web.bind.annotation.*


/* *
 *Created by: Sorata 2017/11/9 0009 上午 11:13
 *
 */
@Api("用户接口")
@RestController
@RequestMapping("/api")
class UserController {

    private val logger: Logger = LoggerFactory.getLogger(javaClass)

    @Autowired lateinit var userService: UserService

    @ApiOperation("根据名字查询一个用户")
    @ApiImplicitParams(
            ApiImplicitParam(value = "名字", name = "name", required = true, dataType = "string", paramType = "path")
    )
    @GetMapping("/user/find/one/{name}")
    fun findOne(@PathVariable name: String) = userService.findByUsername(name) ?: "未找到数据"

    @ApiOperation("根据用户名密码查询")
    @ApiImplicitParams(
            ApiImplicitParam(value = "名字", name = "name", required = true, dataType = "string", paramType = "query"),
            ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "string", paramType = "query")
    )
    @GetMapping("user/find/one/query")
    fun findOne(@RequestParam name: String, @RequestParam password: String) =
            userService.findUser(name, password) ?: "未找到数据"

    @GetMapping("user/find/page")
    fun findPage(@RequestParam name: String, @RequestParam(required = false, defaultValue = "0")
    page: Int, @RequestParam(required = false, defaultValue = "15") limit: Int) = userService.findUserPage(name, page, limit)


}